import { Service } from "egg";
import { TestProps } from "../model/Test";

/**
 * Test Service
 */
export default class TestService extends Service {
  /**
   * sayHi to you
   */
  public async findList() {
    return this.ctx.model.Test.find();
  }

  /**
   * 根据名称信息查新
   * @param {string} name 测试名字
   */
  public findByUsername(name: string) {
    return this.ctx.model.Test.findOne({ name });
  }

  /**
   * 添加数据示范
   * @param data 测试数据
   */
  public async add(data: TestProps) {
    const { ctx } = this;
    const testCreateData: Partial<TestProps> = {
      ...data,
    };
    return await ctx.model.Test.create(testCreateData);
  }
}
